from __future__ import annotations

from typing import List, Set, Union, TYPE_CHECKING

from numpy.lib.function_base import disp
from pyvision.core.Jsonable import Jsonable
from pyvision.core.DataModel import Props
import pandas as pd

if TYPE_CHECKING:
    from pyvision.wrappers.DataSet import DataSet


class RawHtmlProps(Props):

    def __init__(self, html='') -> None:
        super().__init__()
        self.html = html

    def _2json(self):
        return {
            'html': self.html
        }


class TableColumnProps(Props):

    def __init__(self, name: str, display: str) -> None:
        super().__init__()

        self.name = name
        self.display = display

    def _2json(self):
        return {
            'value': self.name,
            'label': self.display
        }


class TableProps(Props):

    def __init__(self, data: DataSet) -> None:
        super().__init__()
        self.data = data
        self.columns: dict[str, TableColumnProps] = {}
        self.styles = {}

    def set_columns(self, column: TableColumnProps):
        self.columns.update({column.name: column})
        return self

    # def set_table_id(self, id: str):
    #     self.data = f'@{id}@'
    #     return self

    def _2json(self):
        return {
            'datasetName': self.data.id,
            'columns': self.columns,
            'styles': self.styles
        }


class AltChartProps(Props):
    def __init__(self, data: DataSet) -> None:
        super().__init__()
        self.data = data
        self.spec = {}
        self.styles = {}

    def _2json(self):
        return {
            'datasetName': self.data.id,
            'spec': self.spec,
            'styles': self.styles
        }


class DataSetProps(Props):
    def __init__(self, dataset_name: str, column_name: str) -> None:
        super().__init__()
        self.dataset_name = dataset_name
        self.column_name = column_name

    def _2json(self):
        return {
            'datasetName': self.dataset_name,
            'columnName': self.column_name
        }


class SlicerProps(Props):

    def __init__(self) -> None:
        super().__init__()
        self.source_set_name: str = ''
        self.datasets: dict[str, DataSetProps] = {}
        self.styles = {}
        self.otherProps = {}

    def set_source(self, dataset_name: str):
        self.source_set_name = dataset_name
        return self

    def attach_dataset(self, ds: DataSetProps):
        if not self.source_set_name:
            self.source_set_name = ds.dataset_name

        self.datasets.update({ds.dataset_name: ds})

        return self

    def _2json(self):
        return {
            'datasetName': self.source_set_name,
            'datasets': [v for v in self.datasets.values()],
            'styles': self.styles,
            'otherProps': self.otherProps,
        }


class SelectProps(SlicerProps):

    def __init__(self) -> None:
        super().__init__()


class DatePickerProps(SlicerProps):

    def __init__(self) -> None:
        super().__init__()
